<?php
//
//	Copyright (c) 2011 Iguana-Farm.com LLC
//

//
//	Chech if this system is already provisioned
//
if (`cat /etc/fstab  | grep sdf` != "")
	die("System already proviosioned\n");

//
//	Get the internal IP of server and make a number from it to be 
//  used as the server_id on mysql config file
//
$ip = `curl -s http://169.254.169.254/latest/meta-data/local-ipv4`;
$server_id = ip2long($ip);
if ($server_id < 0)
	die("Server id is less than zero");

//
//	Make copy of my.cnf and update the server_id
//
system("cat /vol/etc/my.cnf | sed 's/server_id = [0-9]\+/server_id = $server_id/' > /etc/my.cnf");

//
//	Add automont of /vol 
//
system('echo "/dev/sdf /vol xfs noatime 0 0" >> /etc/fstab');

//
//	Configure start MySQL and Apache
//
system('chkconfig --level 345 mysqld on');
system('chkconfig --level 345 httpd on');

system("service mysqld start");
system("service httpd  start");

?>